package example.dawangba.com.z09315222_finalandroidhomework;

import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class FrameActivity extends Activity {

    private SoundPool sp;
    private int id1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_frame);

        ImageView imageView = (ImageView) findViewById(R.id.frame_image);
        imageView.setImageResource(R.drawable.frame_animation);

        Button buttonStart = (Button) findViewById(R.id.start);
        Button buttonPause = (Button) findViewById(R.id.pause);

        sp=new SoundPool(2, AudioManager.STREAM_MUSIC,0);
        id1=sp.load(FrameActivity.this,R.raw.readygo,1);

        final AnimationDrawable frameAnimation = (AnimationDrawable) imageView
                .getDrawable();

        buttonStart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                frameAnimation.start();
                sp.play(id1,1,1,1,0,1);
            }
        });

        buttonPause.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                frameAnimation.stop();
            }
        });
    }
}
